<template>
  <div class="card">
    <div class="card-left">
      <van-image
        width="100%"
        height="70%"
        fit="cover"
        :src="commodity.imgUrl"
      />
    </div>
    <div class="card-right">
      <span class="title">{{ commodity.commodityName }}</span>
      <span class="van-multi-ellipsis--l2 desc">{{
        commodity.commodityDesc
      }}</span>
      <div class="price">
        <span>￥{{ commodity.price }}</span>
        <div class="btn" @click="$emit('toDetail', commodity)">
          选规格
          <div class="tag" v-show="tagValue != 0">{{ tagValue }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import common from "../../utils/common";
import Vue from "vue";
import { Image as VanImage, Overlay } from "vant";

Vue.use(VanImage).use(Overlay);
export default {
  name: "itemCard",
  props: {
    commodity: Object,
  },
  computed: {
    cart() {
      return this.$store.getters.cart;
    },
    tagValue() {
      // console.log("tag:", common.isExist(this.cart, this.commodity));
      return common.isExistById(this.cart, this.commodity);
      
    },
  },
  methods: {},
};
</script>

<style scoped>
.card {
  width: 100%;
  background-color: #fff;
  height: 3rem;
  display: flex;
  flex-direction: row;
  box-sizing: border-box;
  margin: 0.2rem 0;
  /* border: 1px solid #000; */
}
.card-left {
  width: 30%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  /* background-color: #fff; */
}
.card-right {
  width: 65%;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.title {
  font-size: 15px;
  color: #333;
  margin-bottom: 0.1rem;
}
.desc {
  font-size: 11px;
  color: grey;
  margin-bottom: 0.1rem;
}
.price {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}
.price span {
  font-size: 18px;
  color: #333;
}
.price .btn {
  color: #fff;
  background-color: #dba871;
  font-size: 11px;
  width: 1.4rem;
  height: 0.6rem;
  line-height: 0.58rem;
  border-radius: 10px;
  text-align: center;
}
.btn .tag {
  width: 0.3rem;
  height: 0.3rem;
  border-radius: 100%;
  color: #fff;
  background-color: #dba871;
  text-align: center;
  line-height: 0.3rem;
  margin-top: -0.74rem;
  margin-left: 1.15rem;
  border: 2px solid #fff;
}
</style>